package com.qf.boot2302.controller;

import com.qf.boot2302.vo.HelloVo;
import com.qf.boot2302.vo.ResultVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.*;

@RestController
@RequestMapping("/p")
@Validated  // 开启基于注解的校验功能
public class PramcheckController {

    @RequestMapping("/test6")
    public ResultVo test6(@Valid HelloVo helloVo){
        System.out.println(helloVo);
        return ResultVo.ok(1,"ok",helloVo);
    }

    // phonephonephone
    @RequestMapping("/test5")
    public ResultVo test5(@Pattern(regexp = "^1(3[0-9]|4[579]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[89])\\d{8}$",message = "手机号格式不对") String phone){
        System.out.println(phone);
        return ResultVo.ok(1,phone,null);
    }

    @RequestMapping("/test4")
    public ResultVo test4(@Email(message = "email not correct") String mail){
        System.out.println(mail);
        return ResultVo.ok(1,mail,null);
    }

    @RequestMapping("/test1")
    public ResultVo test1(@Size(min = 3,max = 5,message = "长度应该在3-5之间") @NotNull String name){
        System.out.println(name);
        return ResultVo.ok(1,name,null);
    }


    /**
     * @NotEmpty 注解要求name不能为null也不能为空串
     * @param name
     * @return
     */
    @RequestMapping("/test2")
    public ResultVo test2(@NotEmpty String name){
        System.out.println(name);
        return ResultVo.ok(1,name,null);
    }

    /**
     * @NotNull注解要求 name不能为null
     * @param name
     * @return
     */
    @RequestMapping("/test3")
    public ResultVo test3(@NotNull String name){
        System.out.println(name);
        return ResultVo.ok(1,name,null);
    }

}
